package com.usian.admin.controller;

import com.usian.admin.service.AdChannelService;
import com.usian.admin.service.impl.AdChannelServiceImpl;
import com.usian.apis.admin.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.Path;
import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")/*此处可将版本抽取出来*/
@Api(value = "频道管理",tags = "channel",description = "频道管理API")
public class AdChannelController implements AdChannelControllerApi {


    @RequestMapping("/test")//测试
    public String test(){
        return "dsdsds";
    }

    /*
    * 能用Autowired的地方一定能用Resource，但是只能用Resource的地方不一定能用Autowired  (能用小的不用大的)
    * */
    @Autowired
    private AdChannelServiceImpl adChannelService;

    @ApiOperation(value = "查询频道信息",notes = "根据名称分页查询频道列表")
    @ApiImplicitParam(name = "dto",type = "ChannelDto",value = "查询名称")
    @PostMapping("/list")
    @Override
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return adChannelService.findByNameAndPage(dto);
    }


    @ApiOperation(value = "新增频道信息",notes = "新增频道信息")
    @ApiImplicitParam(name = "adchannel",type = "AdChannel",value = "新增频道信息")
    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannel adchannel) {
        return adChannelService.insert(adchannel);
    }


    @ApiOperation(value = "修改频道信息",notes = "根据频道Id修改频道信息")
    @ApiImplicitParam(name = "adChannel",type = "AdChannel",value = "需要修改频道的Id")
    @Override
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }


    @ApiOperation(value = "删除频道信息",notes = "根据频道Id删除频道信息")
    @ApiImplicitParam(name = "id",type = "Integer",value = "需要修改频道的Id")
    @Override
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable Integer id) {
        return adChannelService.deleteById(id);
    }


    @GetMapping("/channels")
    @Override
    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }


}
